package com.helloae;
import java.awt.BorderLayout;

import javax.swing.JFrame;

import com.esri.arcgis.beans.TOC.TOCBean;
import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.controls.ControlsMapFullExtentCommand;
import com.esri.arcgis.controls.ControlsMapPanTool;
import com.esri.arcgis.controls.ControlsMapZoomInTool;
import com.esri.arcgis.controls.ControlsMapZoomOutTool;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.systemUI.esriCommandStyles;

public class EngineVisualBeans{

    public static void main(String[] args)throws Exception{

        //Step 1: Initialize the Java COM Interop.
        EngineInitializer.initializeVisualBeans();

        //Step 2: Initialize a valid License.
        AoInitialize ao = new AoInitialize();
        ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

        //Step 3: Create visual components for the mapviewer.

        //Create a map visual component and load a .mxd map document.
        final String ARCGISHOME = System.getenv("AGSDEVKITJAVA");
        MapBean map = new MapBean();
        map.loadMxFile(ARCGISHOME + "/java/samples/data/mxds/world.mxd", null, null);

        //Create a toolbar visual component and add standard ESRI tools and commands.
        ToolbarBean toolbar = new ToolbarBean();
        toolbar.addItem(ControlsMapZoomInTool.getClsid(), 0, 0, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly);
        toolbar.addItem(ControlsMapZoomOutTool.getClsid(), 0, 0, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly);
        toolbar.addItem(new ControlsMapFullExtentCommand(), 0,  - 1, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly);
        toolbar.addItem(ControlsMapPanTool.getClsid(), 0, 0, false, 0,
            esriCommandStyles.esriCommandStyleIconOnly);

        //Create a table of contents (TOCBean) visual component for the map.
        TOCBean toc = new TOCBean();

        //Buddy up the map component with the toolbar and TOC components.
        toolbar.setBuddyControl(map);
        toc.setBuddyControl(map);

        //Step 4: Build the frame.
        JFrame frame = new JFrame("Hello Arcobjects");
        frame.add(map, BorderLayout.CENTER);
        frame.add(toolbar, BorderLayout.NORTH);
        frame.add(toc, BorderLayout.WEST);
        frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

}